<?php

namespace frontend\models;

use Yii;

/**
 * This is the model class for table "order".
 *
 * @property integer $id
 * @property string $member_id
 * @property string $name
 * @property string $province_name
 * @property string $city_name
 * @property string $area_name
 * @property string $detail_address
 * @property string $tel
 * @property string $delivery_id
 * @property string $delivery_name
 * @property string $delivery_price
 * @property string $pay_type_id
 * @property string $pay_type_name
 * @property string $price
 * @property integer $status
 * @property string $trade_no
 * @property integer $create_time
 * @property integer $update_time
 */
class Order extends \yii\db\ActiveRecord
{
    public static $deliveries = [
        1=>['delivery_id'=>'1','delivery_name'=>'顺丰快递','price'=>20,'evaluation'=>'很快'],
        2=>['delivery_id'=>'2','delivery_name'=>'EMS','price'=>'10','evaluation'=>'稳得起'],
        3=>['delivery_id'=>'3','delivery_name'=>'自提','price'=>'0','evaluation'=>'随时欢迎'],
    ];
    public static $payMethod = [
        1=>['name'=>'货到付款','intro'=>'	送货上门后再收款，支持现金、POS机刷卡、支票支付'],
        2=>['name'=>'在线支付	','intro'=>'	即时到帐，支持绝大数银行借记卡及部分银行信用卡'],
        3=>['name'=>'上门自提	','intro'=>'	自提时付款，支持现金、POS刷卡、支票支付'],
        4=>['name'=>'邮局汇款','intro'=>'	通过快钱平台收款 汇款后1-3个工作日到账'],

    ];

    public static $orderStatus = [0=>'已取消',1=>'待付款',2=>'代发货',3=>'待收获',4=>'完成'];

    public $address_id = 0;
    public $delivery =3;
    public $pay_id = 3;


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'order';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['member_id', 'delivery_id', 'pay_type_id', 'status', 'create_time', 'update_time'], 'integer'],
            [['address_id', 'delivery','pay_id'], 'required'],
            [['delivery_price', 'price'], 'number'],
            [['name', 'detail_address'], 'string', 'max' => 50],
            [['province_name', 'city_name', 'area_name', 'delivery_name'], 'string', 'max' => 30],
            [['tel'], 'string', 'max' => 12],
            [['pay_type_name', 'trade_no'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'member_id' => '会员id',
            'name' => '收货人',
            'province_name' => '省份',
            'city_name' => '城市',
            'area_name' => '区域',
            'detail_address' => '详细地址',
            'tel' => '手机号码',
            'delivery_id' => '配送方式的id',
            'delivery_name' => '配送方式的名称',
            'delivery_price' => '配送价格',
            'pay_type_id' => '支付方式',
            'pay_type_name' => '支付名称',
            'price' => '小计',
            'status' => '订单状态0取消1带付款2待发货3代收获4完成',
            'trade_no' => '交易号',
            'create_time' => '订单创建时间',
            'update_time' => '订单更新时间',
        ];
    }

    public function getOrderDetail()
    {
        return $this->hasMany(OrderDetail::className(),['order_info_id'=>'id'])->all();
    }


}
